home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / NextAnswers / 1440_strong_typing_and_circular_references.rtf < prev    next >
Text File  |  1993-11-08  |  1KB  |  65 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f2\fswiss Helvetica;\f1\fmodern Courier;\f3\fmodern Ohlfs;}
  2. \paperw10900
  3. \paperh9480
  4. \margl120
  5. \margr120
  6. {\colortbl;\red0\green0\blue0;\red84\green84\blue84;\red83\green83\blue83;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ulnone\fs28\fc1\cf1 Q:  I like to use strong typing in my applications but this sometimes causes problems.  For example, take 
  8. \b Bagel.h
  9. \b0 \
  10.  
  11. \f2\fs24\fc0\cf0 \
  12.  
  13. \f1\fc1\cf1     #import <objc/Object.h>\
  14.     #import "Mold.h"\
  15.     \
  16.     @interface Bagel:Object\
  17.     \{\
  18.           Mold *someMold;\
  19.     \}\
  20.     @end\
  21.  
  22. \f0\fs28     \
  23. and 
  24. \b Mold.h
  25. \b0 \
  26. \
  27.  
  28. \f1\fs24     #import <objc/Object.h>\
  29.     #import "Bagel.h"\
  30.     \
  31.     @interface Mold:Object\
  32.     \{\
  33.           Bagel *aBagel;\
  34.     \}\
  35.     @end\
  36.  
  37. \f2\fc0\cf0 \
  38.  
  39. \f0\fs28\fc1\cf1 The compiler doesn't like the circular reference my strong typing causes.  What can I do?\
  40. \
  41. A:  There's no elegant way to avoid this problem.  Modifying 
  42. \b Mold.h
  43. \b0  to look like the following removes the problem:\
  44.  
  45. \f2\fs24\fc0\cf0 \
  46.  
  47. \f1     #import <objc/Object.h>\
  48.     #import "Bagel.h"\
  49.     \
  50.     @interface Mold : Object\
  51.     \{\
  52.           
  53. \b struct
  54. \b0  Bagel *aBagel;\
  55.     \}\
  56.     @end\
  57.  
  58. \f2 \
  59.  
  60. \f0\fs28\fc1\cf1 Valid for 1.0, 2.0, 3.0\
  61. \
  62. QA516            \
  63. \
  64.  
  65.